public class Usuarios
    Inherits dllbase
    Private _Errors As String
    Private _Comments As String
    Private _Return_Value As Integer

    Private _codusuario As Int32
   public property codusuario() as Int32
       get
           return _codusuario
       end get

       set(byval value as Int32)
           _codusuario = value
       end set
   end property

    Private _usuario As String
   public property usuario() as String
       get
           return _usuario
       end get

       set(byval value as String)
           _usuario = value
       end set
   end property

   private _pass as String
   public property pass() as String
       get
           return _pass
       end get

       set(byval value as String)
           _pass = value
       end set
   end property

   private _nombre as String
   public property nombre() as String
       get
           return _nombre
       end get

       set(byval value as String)
           _nombre = value
       end set
   end property

   private _apellido as String
   public property apellido() as String
       get
           return _apellido
       end get

       set(byval value as String)
           _apellido = value
       end set
   end property

   private _ci as Int32
   public property ci() as Int32
       get
           return _ci
       end get

       set(byval value as Int32)
           _ci = value
       end set
   end property

   private _area as Int32
   public property area() as Int32
       get
           return _area
       end get

       set(byval value as Int32)
           _area = value
       end set
   end property

   private _fechaalta as DateTime
   public property fechaalta() as DateTime
       get
           return _fechaalta
       end get

       set(byval value as DateTime)
           _fechaalta = value
       end set
   end property

   private _fechabaja as DateTime
   public property fechabaja() as DateTime
       get
           return _fechabaja
       end get

       set(byval value as DateTime)
           _fechabaja = value
       end set
   end property

   private _active as Boolean
   public property active() as Boolean
       get
           return _active
       end get

       set(byval value as Boolean)
           _active = value
       end set
    End Property


    Public Function AgregarUsuario() As Boolean
        Dim Parametros(8) As String
        Dim ParametroValor(8) As String
        Parametros(0) = "@usuario"
        Parametros(1) = "@pass"
        Parametros(2) = "@nombre"
        Parametros(3) = "@apellido"
        Parametros(4) = "@ci"
        Parametros(5) = "@area"
        Parametros(6) = "@fechaalta"
        Parametros(8) = "@active"
        ParametroValor(0) = _usuario
        ParametroValor(1) = _pass
        ParametroValor(2) = _nombre
        ParametroValor(3) = _apellido
        ParametroValor(4) = _ci
        ParametroValor(5) = _area
        ParametroValor(6) = _fechaalta
        ParametroValor(7) = _active


        If cData.Connect Then
            cData.ErrorsClear()
            If Not cData.ReadDataStoreProcExecute("UsuarioAdd", Parametros, ParametroValor) Then
                _Errors = cData.Errors
            Else
                If cData.Return_Val = "-1" Then
                    _Errors = "El nombre de Usuario ya Existe"
                ElseIf cData.Return_Val = 0 Then
                    AgregarUsuario = True
                End If
            End If

            cData.ReadDataStoreProcClose()
            cData.Disconnect()
        Else
            _Errors = "No se puede conectar a la Base de Datos"
            AgregarUsuario = False
        End If

    End Function
    Public Function Login(ByVal UserName As String, ByVal Password As String) As Boolean
        Dim Parametros(1) As String
        Dim ParametroValor(1) As String
        Parametros(0) = "@usuario"
        Parametros(1) = "@pass"
        ParametroValor(0) = _usuario
        ParametroValor(1) = _pass
        Try
            If cData.Connect() Then
                cData.ErrorsClear()
                If Not cData.ReadDataStoreProcPrepare("UsuarioLogin", Parametros, ParametroValor) Then
                    _Errors = cData.Errors
                    Login = False
                Else
                    cData.ReadDataStoreProcPrepareExecute()
                    If cData.ReadHaveData Then Login = True
                End If
                cData.ReadDataStoreProcClose()
                cData.Disconnect()
            Else
                Login = False
                _Errors = "No se puede Conectar a la Base de Datos"
            End If
        Catch ex As Exception
            Login = False
            _Errors = ex.Message
        End Try
    End Function
    Public Function GetPassword() As String
        Dim Parametros(0) As String
        Dim ParametroValor(0) As String
        Parametros(0) = "@usuario"
        Parametros(1) = "@pass"
        ParametroValor(0) = My.User.Name

        If cData.Connect() Then
            cData.ReadDataStoreProcPrepare("UserGetPassword", Parametros, ParametroValor)
            Dim a As Data.DataSet = cData.ReadDataStoreProc
            GetPassword = cData.ReadSP("Password")
            'GetPassword = a.Tables(0).Rows(0).Item("Password")
            cData.ReadDataStoreProcClose()
            cData.Disconnect()
        End If
    End Function
    Public Function ChangePassword(ByVal NewP As String) As Boolean
        Dim Parameters(1) As String, ParametersValue(1) As String
        Parameters(0) = "@usuario"
        ParametersValue(0) = My.User.Name
        Parameters(1) = "@Password"
        ParametersValue(1) = NewP
        If cData.Connect() Then
            If Not cData.ReadDataStoreProcExecute("UserChangePassword", Parameters, ParametersValue) Then
                ChangePassword = False
            Else
                ChangePassword = True
            End If
            cData.ReadDataStoreProcClose()
            cData.Disconnect()
        End If
    End Function

    Public Function UserDelete(ByVal ID As Integer) As Boolean
        Dim Parameters(0) As String, ParametersValue(0) As String
        Parameters(0) = "@codusuario"
        ParametersValue(0) = codusuario
        Try
            If cData.Connect() Then
                cData.ErrorsClear()
                If cData.ReadDataStoreProcExecute("UserDelete", Parameters, ParametersValue) Then
                    If cData.Return_Val = 0 Then
                        UserDelete = True
                    Else
                        _Errors = "Usuario no existia."
                    End If
                Else
                    _Errors = cData.Errors
                    UserDelete = False
                End If
                cData.ReadDataStoreProcClose()
                cData.Disconnect()
            Else
                _Errors = "No se pudo conectar con la base de datos."
                UserDelete = False
            End If
        Catch ex As Exception
            _Errors = ex.Message
        End Try
    End Function

end class
